/*
 * list_test.c
 *
 *  Created on: 02/11/2010
 *      Author: Rafael
 *
 *  Description: test routines for the linked list container
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include "../DataCarriers/linked_list.h"


int include()
{
	list l = ll_create();

	ll_add(l, "item1");
	ll_add(l, "item2");
	ll_add(l, "item3");
	ll_add(l, "item4");
	ll_add(l, "item5");
	ll_add(l, "item6");

	ll_print(l);

	return 1;
}

int retrieve()
{
	list l = ll_create();

	ll_add(l, "item1");
	ll_add(l, "item2");
	ll_add(l, "item3");
	ll_add(l, "item4");
	ll_add(l, "item5");
	ll_add(l, "item6");

	ll_print(l);

	printf("position 0 holds: %s\n", ll_get(l, 0));
	printf("position 1 holds: %s\n", ll_get(l, 1));
	printf("position 2 holds: %s\n", ll_get(l, 2));
	printf("position 3 holds: %s\n", ll_get(l, 3));
	printf("position 4 holds: %s\n", ll_get(l, 4));
	printf("position 5 holds: %s\n", ll_get(l, 5));
	printf("position 6 holds: %s\n", ll_get(l, 6));
	return 1;
}

int find()
{
	list l = ll_create();

	ll_add(l, "item1");
	ll_add(l, "item2");
	ll_add(l, "item3");
	ll_add(l, "item4");
	ll_add(l, "item5");
	ll_add(l, "item6");

	ll_print(l);

	printf("'item7' is in position: %d\n", ll_find(l, "item7"));
	printf("'item6' is in position: %d\n", ll_find(l, "item6"));
	printf("'item5' is in position: %d\n", ll_find(l, "item5"));
	printf("'item4' is in position: %d\n", ll_find(l, "item4"));
	printf("'item3' is in position: %d\n", ll_find(l, "item3"));
	printf("'item2' is in position: %d\n", ll_find(l, "item2"));
	printf("'item1' is in position: %d\n", ll_find(l, "item1"));
	printf("'item0' is in position: %d\n", ll_find(l, "item0"));

	return 1;
}

int delete()
{
	list l = ll_create();

	ll_add(l, "item0");
	ll_add(l, "item1");
	ll_add(l, "item2");
	ll_add(l, "item3");
	ll_add(l, "item4");
	ll_add(l, "item5");

	ll_print(l);
	ll_remove(l, 3);
	ll_print(l);
	ll_remove(l, 0);
	ll_print(l);

	return 1;
}

int main(int argc, char** argv)
{
	include();
	retrieve();
	find();
	delete();
	return 0;
}
